package com.golddaymicromall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.golddaymicromall.activity.R;
import com.golddaymicromall.bean.ProductInfo;
import com.golddaymicromall.img.ImageLoad;
import com.golddaymicromall.model.HttpModel;
import java.util.List;

/**
 * Created by dawd on 2016/3/11.
 */
public class ConfirmPayAdapter extends BaseAdapter {
    private List<ProductInfo> list;
    private Context ctx;
    private ImageLoad load;
    private int selectID;
    LayoutInflater layoutinflater;

    public ConfirmPayAdapter(List<ProductInfo> list, Context ctx) {
        this.list = list;
        this.ctx = ctx;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    // 自定义的选中方法
    public void setSelectID(int position) {
        selectID = position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder hold;
        View view = convertView;
        if (view == null) {
            hold = new ViewHolder();
            layoutinflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            view = layoutinflater.inflate(R.layout.item_confirmpay, null);
            hold.goodsImg = (ImageView) view.findViewById(R.id.SeCondPurchaseItem_Img);
            hold.priceTv = (TextView) view.findViewById(R.id.SeCondPurchaseItem_PriceTv);
            hold.titleTv = (TextView) view.findViewById(R.id.SeCondPurchaseItem_TitleTv);
            hold.second_jia = (TextView) view.findViewById(R.id.second_jia);
            hold.second_jian = (TextView) view.findViewById(R.id.second_jian);
            hold.second_count = (TextView) view.findViewById(R.id.second_count);
            view.setTag(hold);

        } else {
            hold = (ViewHolder) view.getTag();

        }
        Glide
                .with(ctx)
                .load(new HttpModel().IMGURL+list.get(position).getImage())
                .into(hold.goodsImg);
        hold.priceTv.setText("￥" + list.get(position).getPrice());
        hold.titleTv.setText(list.get(position).getProductname());
        hold.second_count.setText(list.get(position).getCount() == 0 ? "0" : String.valueOf(list.get(position).getCount()));
        return view;
    }



    public static class ViewHolder {
        ImageView goodsImg;
        TextView titleTv;
        TextView priceTv;
        TextView second_jian;
        TextView second_jia;
        TextView second_count;
    }
}
